package com.shaw.workrecord.controller;

import com.shaw.workrecord.entity.PageRequest;
import com.shaw.workrecord.entity.PageResponse;
import com.shaw.workrecord.entity.ResponseBean;
import com.shaw.workrecord.pojo.game.request.DintWordGroupAddRequest;
import com.shaw.workrecord.pojo.game.request.DintWordGroupEditRequest;
import com.shaw.workrecord.pojo.game.response.DintWordGroupResponse;
import com.shaw.workrecord.service.IDintWordGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author jiangjunhui
 * @description
 * @date 2022/9/15 16:20
 */
@RestController
@Api(tags = "谁是卧底游戏模块")
@Validated
public class DintWordGroupController {

    @Autowired
    private IDintWordGroupService service;

    @GetMapping("/dintWordGroup")
    @ApiOperation("获取单词组")
    public ResponseBean<PageResponse<DintWordGroupResponse>> getPage(PageRequest request) {
        return ResponseBean.success(service.getWordPage(request));
    }

    @PostMapping("/dintWordGroup")
    @ApiOperation("新增单词组")
    public ResponseBean<Boolean> addWord(@RequestBody DintWordGroupAddRequest request) {
        if (service.addWord(request)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("新增失败");
    }

    @PutMapping("/dintWordGroup")
    @ApiOperation("新增单词组")
    public ResponseBean<Boolean> editWord(@RequestBody DintWordGroupEditRequest request) {
        if (service.editWord(request)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("新增失败");
    }

    @DeleteMapping("/dintWordGroup/{id}")
    @ApiOperation("删除单词组")
    public ResponseBean<Boolean> addWord(@PathVariable("id") Long id) {
        if (service.deleteWord(id)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("删除失败");
    }


}
